package okl.tdf.components
{
	import mx.formatters.DateFormatter;
	
	import spark.components.Label;
	
	/**
	 *  Displays formatted time using <code>timeFormat</code>
	 * 
	 *  @see  mx.formatters.DateFormatter#formatString for format details
	 *	@author "oleksandr.kulinchenko@gmail.com"
	 */
	public class TimeLabel extends Label
	{
		public function TimeLabel()
		{
			super();
		}
		
		private static var timeFormatter:DateFormatter = new DateFormatter();
		
		//{region CLASS_INTERFACE
		private var _targetTime:Date;
		
		/**
		 * Date since duration text should be displayed
		 */
		public function get targetTime():Date
		{
			return _targetTime;
		}
		
		public function set targetTime(value:Date):void
		{
			if(value==targetTime)return;
			_targetTime = value;
			
			invalidateText();
		}
		
		private var _timeFormat:String = "HH:NN:SS";
		/**
		 * 
		 *@default "HH:NN:SS"
		 */
		public function get timeFormat():String
		{
			return _timeFormat;
		}

		public function set timeFormat(value:String):void
		{
			if(value==timeFormat)return;
			_timeFormat = value;			

			invalidateText();
		}
		//}endregion
		
		//{region INTER_LOGIC
		private function invalidateText():void{
			if(targetTime==null){
				text="";
				return;
			}
			timeFormatter.formatString = timeFormat;
			this.text = timeFormatter.format(targetTime);
		} 
		//}endregion

	}
}